var mapQuery = {
    map: null,
    center: null,
    cityId: null,
    wgsCenter: null,
    vector: null,
    jiaoyu: null,
    jiantong: null,
    yiliao: null,
    gouwu: null,
    shenghuo: null,
    yule: null,
    buffer: null,
    overly: null,
    arrBuffer: null,
    oldExt: null,
    boundFeat:null,
    rqInfoCount: null,
    rqInfoName:null,
    rqInfoId:null,
    InfoSource:null,
    pan:null,
    init: function (cityId, zoom, center) {
        if (communityId == null || communityId == '') {
            return;
        }
        this.center = center;
        this.cityId = cityId;
        this.wgsCenter = ol.proj.transform(center, 'EPSG:3857', 'EPSG:4326')
        this.map = xdmap.mapInit('mapQuery', zoom, this.center);
        this.vector = new ol.layer.Vector()
        this.createClickPopup();
        this.vector.set('id', 'bound');
        this.vector.setVisible(false);
        this.map.addLayer(this.vector);
        mapQuery.map.getView().on('change:resolution', function (e) {
            mapQuery.onResChange(e);
        });
        mapQuery.map.getInteractions().forEach(function(element,index,array) {
            if (element instanceof ol.interaction.DragPan) {
                mapQuery.pan = element;
            }
        });
        //mapQuery.pan.setActive(false);
        var selectImgSrc = '../../assets/education_map.png';
        mapQuery.addLy('教育', '小学', 2, selectImgSrc, cityId, communityId);
        // setTimeout(function () {
        //     mapQuery.map.getView().setCenter([mapQuery.center[0] + 1000, mapQuery.center[1] + 1000])
        // }, 1000)

    },
    /*
    * 创建悬浮窗
    * */
    createClickPopup: function () {
        var poiInfo = document.getElementById('poi');
        this.overly = new ol.Overlay({
            element: poiInfo,
            autoPan: true,
            offset: [-60, -55],
            autoPanAnimation: {
                duration: 250
            }
        });
        this.map.addOverlay(this.overly);
    },
    changeStyle: function (data,src) {
        mapQuery.map.getOverlays().forEach(function (overly) {
            if (overly.N.poiId == data) {
                mapQuery.setHousing(data,src);
                mapQuery.map.getView().setZoom(16);
                mapQuery.map.getView().setCenter(overly.N.position);
            }

        })
    },
    changeStyleNoLocation: function (data,src) {
        mapQuery.map.getOverlays().forEach(function (overly) {
            if (overly.N.poiId == data) {
                mapQuery.setHousing(data,src);
            }

        })
    },
    //地图缩放事件
    onResChange: function (e) {
        $(".gisName").hide();
        mapQuery.vector.setVisible(false);
        var id = mapQuery.vector.getSource().get('id');
        var zoom = mapQuery.map.getView().getZoom();
        if (zoom >= 18) {
            $(".gisName").css("display","flex");
            mapQuery.vector.setVisible(true);
        }
    },
    query: function (cityId, type, center, distance, callback) {
        var geo = null;

        if (distance == 0) {
            var ext = map.getView().calculateExtent();
            geo = ol.geom.Polygon.fromExtent(ext);
        } else {
            var ep3 = new ol.proj.Projection({
                code: 'EPSG:3857'
            });
            var ep4 = new ol.proj.Projection({
                code: 'EPSG:4326'
            });

            var parser = new jsts.io.OL3Parser();
            var geom = new ol.geom.Point(center);
            // 将openlayers图形转换为jsts几何图形
            var jstsGeom = parser.read(geom);
            var buffered = jstsGeom.buffer(distance * 1000);
            geo = parser.write(buffered)
        }
        var request = new ol.format.WFS().writeGetFeature({
            srsName: 'EPSG:3857',
            featureNS: 'www.xdeps.com',
            featurePrefix: 'esp',
            featureTypes: ['gp_address_poi_1101'],
            outputFormat: 'application/json',
            filter: ol.format.filter.and(
                ol.format.filter.equalTo('symbol_id', type),
                ol.format.filter.within('shape', geo, 'EPSG:3857')
            )
        });
        var body = new XMLSerializer().serializeToString(request);
        fetch('https://map-geoserver.cindata.cn/geoserver/wfs', {
            method: 'POST',
            body: body
        }).then(function (response) {
            return response.json();
        }).then(function (json) {
            callback(json)
        });
    },
    /*
  * 清除除了id之外的图层
  * */
    removeOther: function (id) {
        var map = mapQuery.map;
        map.getLayers().forEach(function (t) {
            if (t != null) {
                var lyId = t.get('id');
                if (lyId != null) {
                    if (lyId != id) {
                        if (lyId != 'base') {
                            mapQuery.map.removeLayer(t);
                        }
                    }
                }
            }
        })
    },
    /*
      * 周边配套加载
      * */
    queryGeoServer: function (cityId, type, center, distance,url, callback) {
        var geoExt = null
        var filter = null;
        var geo = new ol.geom.Circle(center,distance*1000);
        mapQuery.oldExt =  mapQuery.map.getView().calculateExtent();
        if (distance == 0) {
            geoExt = map.getView().calculateExtent();
        } else {
            geoExt = (new ol.geom.Circle(center,distance*1000)).getExtent();
        }
        var lyName = 'gp_address_poi_' + cityId.toString().substring(0,4);
        switch (type) {
            case 109:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>111</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 112:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>112</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 110:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>110</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 361:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>362</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 350:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>351</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 54:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>55</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 56:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>58</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 156:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>157</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 158:
                filter =
                    'filter=' +
                    '<PropertyIsEqualTo>' +
                    '<PropertyName>symbol_id</PropertyName>' +
                    '<Literal>159</Literal>' +
                    '</PropertyIsEqualTo>'
                break;
            case 237:
                filter =
                    'filter=' +
                    '<PropertyIsBetween>' +
                    '<PropertyName>symbol_id</PropertyName> ' +
                    '<LowerBoundary>' +
                    ' <Literal>220</Literal> ' +
                    '</LowerBoundary>' +
                    ' <UpperBoundary> ' +
                    '<Literal>241</Literal> ' +
                    '</UpperBoundary>' +
                    ' </PropertyIsBetween>'
                break;
            case 319:
                filter =
                    'filter=' +
                    '<PropertyIsBetween>' +
                    '<PropertyName>symbol_id</PropertyName> ' +
                    '<LowerBoundary>' +
                    ' <Literal>304</Literal> ' +
                    '</LowerBoundary>' +
                    ' <UpperBoundary> ' +
                    '<Literal>337</Literal> ' +
                    '</UpperBoundary>' +
                    ' </PropertyIsBetween>'
                break;
            case 415:
                filter =
                    'filter=' +
                    '<PropertyIsBetween>' +
                    '<PropertyName>symbol_id</PropertyName> ' +
                    '<LowerBoundary>' +
                    ' <Literal>415</Literal> ' +
                    '</LowerBoundary>' +
                    ' <UpperBoundary> ' +
                    '<Literal>416</Literal> ' +
                    '</UpperBoundary>' +
                    ' </PropertyIsBetween>'
                break;
        }
        var url =
            'https://map-geoserver.cindata.cn/geoserver/eps/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=eps:gp_address_poi_' +
            cityId.toString().substring(0, 4) +
            '&outputFormat=application%2Fjson&srsname=EPSG:3857&maxFeatures=5000&' + filter
        '&bbox=' + geoExt.join(',') + ',EPSG:3857';
        /*
        * 必须用原生请求,否则会出现跨域问题
        * */
        var ajax = new XMLHttpRequest();
        ajax.open('get', url);
        ajax.onreadystatechange = function (data) {
            if (ajax.readyState == 4 && ajax.status == 200) {
                var text = data.currentTarget.responseText;
                var json = eval('(' + text + ')');
                var features = new ol.format.GeoJSON().readFeatures(json);
                var result = new Array();
                var condition = null;
                features.forEach(function (feat) {
                    var point = feat.getGeometry().getCoordinates();
                    if (geo.intersectsCoordinate(point)) { // 4.6X版本自带的api
                        if (type == '109'){
                            condition = (feat.N.symbol_id == 111);
                        } else if (type == '112'){
                            condition = (feat.N.symbol_id == 112);
                        }
                        else if (type == '110'){
                            condition = (feat.N.symbol_id == 110);
                        }
                        else if (type == '361'){
                            condition = (feat.N.symbol_id == 362);
                        } else if (type == '350') {
                            condition = (feat.N.symbol_id == 351);
                        }else if (type == '237'){
                            condition = (feat.N.symbol_id >= 220 && feat.N.symbol_id <= 241);
                        } else if (type == '319'){
                            condition = (feat.N.symbol_id >= 304 && feat.N.symbol_id <= 337);
                        } else if (type == '415'){
                            condition = (feat.N.symbol_id >= 415 && feat.N.symbol_id <= 416);
                        } else if (type == '54'){
                            condition = (feat.N.symbol_id == 55 );
                        } else if (type == '56'){
                            condition = (feat.N.symbol_id == 58 );
                        }else if (type == '158'){
                            condition = (feat.N.symbol_id == 159 );
                        }else if (type == '156'){
                            condition = (feat.N.symbol_id == 157 );
                        }
                        if (condition) {
                            var shp = new ol.Sphere(6378137);
                            var po = feat.N.geometry.A;
                            var ep3 = new ol.proj.Projection({code: 'EPSG:3857'});
                            var ep4 = new ol.proj.Projection({code: 'EPSG:4326'});
                            var c1 = ol.proj.transform(center, ep3, ep4);
                            var c2 = ol.proj.transform(po, ep3, ep4);
                            var distance = shp.haversineDistance(c1, c2);
                            if (distance != null && distance != '') {
                                distance = distance.toFixed(0);
                            } else {
                                distence = '--';
                            }
                            feat['distance'] = distance;
                            result.push(feat)
                        }
                    }
                })
                callback(result)
            }
        }
        ajax.send();
    },
    communityBound: function(city,communityId){
        if(mapQuery.vector != null){
            mapQuery.map.removeLayer(mapQuery.vector)
        }
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader:function () {
                $.ajax({
                    url: '/map/mapBuildingBankData2',
                    type: 'POST',
                    async: true,
                    data: {
                        city: city,
                        communityId: communityId
                    },
                    success: function (data) {
                        if (data.result.community == null) {
                            return;
                        }
                        var rqInfocCenter = [data.result.community.arcgisX, data.result.community.arcgisY];
                        mapQuery.boundFeat = xdmap.tool.createFeatureForWKT(data.result.community.bound);
                        mapQuery.boundFeat.setStyle(new ol.style.Style({
                            stroke: new ol.style.Stroke({
                                color: 'rgba(250,176,117,1)',
                                width: 2
                            }),
                            fill: new ol.style.Fill({
                                color: 'rgba(255,179,91,0.2)'
                            })
                        }))
                        mapQuery.boundFeat.set('info', 'rqBound');
                        source.addFeature(mapQuery.boundFeat); //小区边界
                        //小区中心
                        var communityName = '';
                        var hourseCount = 0;
                        if( data.result.community.communityName){
                            communityName = data.result.community.communityName;
                        }
                        if( data.result.community.totalHouseHoldCount){
                            mapQuery.hourseCount = data.result.community.totalHouseHoldCount;
                        }
                        if(data.result.community.totalBuildingCount){
                            mapQuery.rqInfoCount = data.result.community.totalBuildingCount;
                        }
                        if( data.result.community.communityName){
                            mapQuery.rqInfoName = data.result.community.communityName;
                        }
                        if(data.result.community.communityName){
                            mapQuery.rqInfoName = data.result.community.communityName;
                        }
                        mapQuery.rqInfoId =  communityId;
                        var div = mapQuery.createRightDivs(communityName, hourseCount);
                        var centerOverly = new ol.Overlay({
                            element: div,
                            position: rqInfocCenter,
                            offset: [-10, -30],
                            autoPan: true,
                            autoPanAnimation: {
                                duration: 250
                            }
                        })
                        mapQuery.map.addOverlay(centerOverly);
                        //小区楼栋
                        var divList = mapQuery.createDiv(data.result.mapDataList);
                        divList.forEach(function (item) {
                            var div = item[0];
                            //var point = ol.proj.transform(item[1], 'EPSG:4326', 'EPSG:3857');
                            var point = item[1];
                            var overly = new ol.Overlay({
                                element: div,
                                position: point,
                                offset: [-10, -30],
                                autoPan: true,
                                autoPanAnimation: {
                                    duration: 250
                                }
                            })
                            mapQuery.map.addOverlay(overly);
                        })
                        //mapQuery.showOverly();
                    }
                })
            }
        })

        mapQuery.vector = new ol.layer.Vector({
            source:source
        })
        mapQuery.map.addLayer(mapQuery.vector)
        // source.set('id', 'Info');
        // mapQuery.InfoSource = source;
    },
    addLy: function (lytype, type, m,src,city,communityId) {
        mapQuery.map.getOverlays().clear();
        var imgSrc = null;
        var selectImgSrc = null;
        var id = null;
        var url = null;
        var bufferCenter = mapQuery.center;
        this.arrBuffer = new Array();
        mapQuery.communityBound(city, communityId);
        switch (lytype) {
            case '教育': {
                if (type == '小学') {
                    type = 109;
                    id = 'xiaoxue';
                } else if (type == '中学') {
                    type = 112;
                    id = 'zhongxue';
                } else if (type == '幼儿园') {
                    type = 110;
                    id = 'youeryuan';
                }
                url = '../../assets/school_.png';
                imgSrc = '../../assets/education1_map.png';
                selectImgSrc = '../../assets/education_map.png';
            }
                break;
            case '交通': {
                var id = null;
                if (type == '地铁') {
                    type = 54;
                    id = 'ditie'
                } else if (type == '公交') {
                    type = 56;
                    id = 'gongjiao'
                }
                url = '../../assets/traffic_.png';
                imgSrc = '../../assets/traffic1_map.png'
                selectImgSrc = '../../assets/traffic_map.png';
            }
                break;
            case '医疗': {
                type = 319;
                id = 'yiliao';
                url = '../../assets/hostptail_.png';
                imgSrc = '../../assets/medical1_map.png'
                selectImgSrc = '../../assets/medical_map.png'
            }
                break;
            case '购物': {
                var id = null;
                if (type == '商场') {
                    type = 158;
                    id = 'shangchang'
                } else if (type == '超市') {
                    type = 156;
                    id = 'chaoshi'
                }
                url = '../../assets/shopping_.png';
                imgSrc = '../../assets/shopping1_map.png'
                selectImgSrc = '../../assets/shopping_map.png';
            }
                break;
            case '娱乐': {
                type = 350;
                id = 'yule'
                url = '../../assets/playing_.png';
                imgSrc = '../../assets/entertainment1_map.png';
                selectImgSrc = '../../assets/entertainment_map.png';
            }
                break;
            case '生活': {
                type = 361;
                id = 'shenghuo';
                url = '../../assets/life_.png';
                imgSrc = '../../assets/life1_map.png';
                selectImgSrc = '../../assets/life_map.png';
            }
                break;
        }
        var i = 0;
        mapQuery.queryGeoServer(mapQuery.cityId, type, bufferCenter, m, url, function (data) {
            mapQuery.loadList(data, url, selectImgSrc)
            data.forEach(function (feature) {
                var div = mapQuery.setHousing(feature.N, imgSrc, 'poi', selectImgSrc, feature.N.poi_id);
                var overlay = xdmap.overlay.createOverlay(id, div[0], feature.N.geometry.A, [0, 0]);
                overlay.set('id', id);
                if (feature.N.poi_id) {
                    overlay.set('poiId', feature.N.poi_id);
                }
                mapQuery.map.addOverlay(overlay);
                i++;
            })
        });
    },
    showOverly: function () {
        var eleOverlys = $('.ol-overlay-container.ol-selectable');
        for (var i = 0; i < eleOverlys.length; i++) {
            var div = eleOverlys[i];
            var dis = div.style.display;
            if (dis != 'block') {
                div.style.display = 'block';
            }
        }
    },
    //创建悬浮窗
    createRightDivs: function (inputData, hourseCount) {
        var div = this._div = document.createElement("div");
        var estateCount =  mapQuery.rqInfoCount?mapQuery.rqInfoCount:'0';
        var img = document.createElement('img');
        img.src = '/assets/accountLogo/zhoubian.png';
        div.style.position = "absolute";
        div.style.cursor = 'pointer';
        div.style.zIndex = '1';
        var message = document.createElement('div');
        message.className = "message"
        message.style.position = 'absolute';
        message.style.border = '1px solid rgb(98, 203, 49)';
        message.style.background = '#fff';
        message.style.borderRadius = '6px';
        message.style.width = '160px';
        message.style.top = '-60px';
        message.style.left = '-63px';
        message.style.textAlign = 'center';
        var header = document.createElement('h5');
        header.innerHTML = mapQuery.rqInfoName;
        header.style.fontWeight = 'bold';
        header.style.color = '#62cb31';
        message.appendChild(header);
        var body = document.createElement('p');
        // body.innerHTML = '已押总量:<strong> ' +estateCount + '</strong>&nbsp;&nbsp;&nbsp;总户数:<strong> ' + hourseCount + '</strong>';
        message.appendChild(body);
        var sj = this._p = document.createElement("p");
        sj.style.position = "absolute";
        sj.style.width = 0;
        sj.style.height = 0;
        sj.style.borderLeft = "10px solid transparent";
        sj.style.borderRight = "10px solid transparent";
        sj.style.bottom = "-20px";
        sj.style.left = '71px';

        sj.style.borderTop = "10px solid #62cb31";
        message.appendChild(sj);
        div.appendChild(message);
        div.appendChild(img);
        message.onclick = function () {
            var href = location.origin + '/estate/index?communityId=' + mapQuery.rqInfoId + '&city=' + mapQuery.cityId;
            window.open(href);
        };
        img.onclick = function () {
            $(this).siblings('div').toggle();
        };
        return div;
    },
    //楼栋覆盖物
    createDiv: function (paramsData) {
        var resultList = new Array();
        var tmpList = new Array();
        var resultList, topDiv, sj, lastSmall, oneSmall;
        paramsData.forEach(function (searchEstate) {
            var div = document.createElement("div");
            div.className = "gisName";
            searchEstate.forEach(function (data, i) {
                //自定义楼栋覆盖物
                var smallDiv;
                if (i != 0) {
                    if (oneSmall) oneSmall.style.padding = "6px 18px 6px 10px";
                    smallDiv = document.createElement('div');
                    smallDiv.appendChild(document.createTextNode(data.estateList.length + '笔'));
                    smallDiv.style.padding = "6px 18px 6px 10px";
                    smallDiv.style.borderRadius = '8px';
                    smallDiv.style.marginLeft = '-10px';
                    if (data.estateList[0].define == '中风险') {
                        smallDiv.style.backgroundColor = "#FF9800";
                    } else if (data.estateList[0].define == '低风险') {
                        smallDiv.style.backgroundColor = "#62CB31";
                    } else if (data.estateList[0].define == '高风险') {
                        smallDiv.style.backgroundColor = "#E51C23";
                    } else if (data.estateList[0].define == '亏损') {
                        smallDiv.style.backgroundColor = "#8B1818";
                    }
                    lastSmall = smallDiv;
                    topDiv.appendChild(smallDiv);
                } else {
                    if (lastSmall) lastSmall.style.padding = '6px 10px';

                    div.style.position = "absolute";
                    div.style.color = "white";
                    div.style.opacity = '0.95';
                    div.style.display = 'flex';
                    div.style.whiteSpace = "nowrap";
                    div.style.MozUserSelect = "none";
                    div.style.fontSize = "12px";
                    div.style.cursor = "pointer";
                    smallDiv = document.createElement('div');
                    smallDiv.appendChild(document.createTextNode(data.estateList.length + '笔'));
                    smallDiv.style.padding = "6px 10px";
                    smallDiv.style.borderRadius = "8px";
                    div.appendChild(smallDiv);
                    sj = this._p = document.createElement("p");
                    if (data.estateList[0].define == '中风险') {
                        smallDiv.style.backgroundColor = "#FF9800";
                        sj.style.borderTop = "10px solid #FF9800";
                    } else if (data.estateList[0].define == '低风险') {
                        smallDiv.style.backgroundColor = "#62CB31";
                        sj.style.borderTop = "10px solid #62CB31";
                    } else if (data.estateList[0].define == '高风险') {
                        smallDiv.style.backgroundColor = "#E51C23";
                        sj.style.borderTop = "10px solid #E51C23";
                    } else if (data.estateList[0].define == '亏损') {
                        smallDiv.style.backgroundColor = "#8B1818";
                        sj.style.borderTop = "10px solid #8B1818";
                    }
                    sj.style.position = "absolute";
                    sj.style.width = 0;
                    sj.style.height = 0;
                    sj.style.borderLeft = "10px solid transparent";
                    sj.style.borderRight = "10px solid transparent";
                    sj.style.bottom = "-20px";
                    sj.style.left = '6px';
                    div.appendChild(sj);
                    oneSmall = smallDiv;
                    lastSmall = null;
                    topDiv = div;
                }
                $(topDiv).hover(function () {
                    $(this).css('z-index', 11);
                }, function () {
                    $(this).css('z-index', 'auto')
                });
                topDiv.onclick = function () {
                    $(this).parent().siblings().children().children("div.row").css("display", "none");
                    $(this).parent().siblings().children().css('zIndex', 'auto');
                    $(this).css('zIndex', '11')
                    $(this).children('div.row').toggle();
                    if ($(this).children('div.row').length >= 1) return;
                    var listDiv = document.createElement("div");
                    listDiv.style.position = 'absolute';
                    listDiv.style.left = this.offsetWidth + 14 + "px";
                    listDiv.style.color = '#6a6c6f';
                    listDiv.style.width = '400px';
                    listDiv.style.whiteSpace = 'normal';
                    listDiv.className = 'row';
                    var col = document.createElement("div");
                    var hpanel = document.createElement("div");
                    hpanel.className = 'hpanel';
                    var hpanelHead = document.createElement("div");
                    hpanelHead.className = 'panel-heading hbuilt';
                    hpanelHead.onclick = function (e) {
                        e.stopPropagation()
                    };
                    var panelTools = document.createElement('div');
                    panelTools.className = 'panel-tools';
                    var closebox = document.createElement('a');
                    var closeIcon = document.createElement('i');
                    closeIcon.className = 'fa fa-times';
                    closebox.appendChild(closeIcon);
                    closebox.className = 'closebox';
                    var that = $(this);
                    closebox.onclick = function () {
                        that.children("div.row").css("display", "none");
                    };
                    panelTools.appendChild(closebox);
                    hpanelHead.appendChild(panelTools);
                    var aHref = document.createElement('a');
                    aHref.appendChild(document.createTextNode(data.estateList[0].communityname));
                    aHref.setAttribute('href', location.origin + '/estate/index?communityId=' + mapQuery.rqInfoId);
                    hpanelHead.appendChild(aHref);
                    var hpanelBody = document.createElement("div");
                    hpanelBody.className = 'panel-body no-padding';
                    hpanelBody.style.maxHeight = '190px';
                    hpanelBody.style.overflowY = 'auto';
                    var listGroup = document.createElement('ul');
                    listGroup.className = 'list-group';
                    var hpanelFoot = document.createElement('div');
                    hpanelFoot.className = 'panel-footer';
                    hpanelBody.appendChild(listGroup);
                    hpanel.appendChild(hpanelHead);
                    hpanel.appendChild(hpanelBody);
                    hpanel.appendChild(hpanelFoot);
                    col.appendChild(hpanel);
                    listDiv.appendChild(col);
                    this.appendChild(listDiv);
                    searchEstate.forEach(function (data) {
                        var itemData = data.estateList;
                        itemData.forEach(function (data) {
                            var item = document.createElement('li');
                            item.className = 'list-group-item ';
                            var badge = document.createElement('span');
                            badge.className = 'badge badge-info';
                            badge.innerHTML = data.cltv + '%';
                            item.appendChild(badge);
                            if (data.define == '中风险') {
                                badge.style.backgroundColor = "#FF9800";
                            } else if (data.define == '低风险') {
                                badge.style.backgroundColor = "#62CB31";
                            } else if (data.define == '高风险') {
                                badge.style.backgroundColor = "#E51C23";
                            } else if (data.define == '亏损') {
                                badge.style.backgroundColor = "#8B1818";
                            }
                            item.appendChild(document.createTextNode(data.sourceaddress));
                            item.onclick = function () {
                                var href = window.location.origin + "/estate/mapShow/" + data.id;
                                window.open(href);
                            };
                            listGroup.appendChild(item);
                        });
                    });
                    var listLength = listGroup.children.length;
                    hpanelFoot.innerHTML = '共 ' + listLength + ' 笔';
                };
            });
            if (searchEstate.length > 0) {
                tmpList = new Array();
                tmpList[0] = topDiv;
                tmpList[1] = [searchEstate[0].lng, searchEstate[0].lat];
                resultList.push(tmpList);
            }
            div.style.display = "none";

        });
        return resultList;
    },
    /*搜索结果地图位置*/
    setHousing: function (data,unSelectImgSrc, type, selectImgSrc,id) {
        if(arguments.length < 3){
            var width = $('.'+data+' div').outerWidth();
            $('.'+data+' div').show().css('left', -(width / 2 - 20));
            $('.'+data+' p').show();
            $('.'+data+' h6').css('background-image', 'url(' + unSelectImgSrc + ')');
            $('.'+data+'').css('z-index','10');
            $('.'+data+'').parent().siblings().children().css('z-index','auto');
            $('.'+data+'').parent().siblings().children().children('div').hide();
            $('.'+data+'').parent().siblings().children().children('p').hide();
            $('.'+data+'').parent().siblings().children().children('h6').css('background-image', 'url('+$('.'+data+' h6').attr('oldsrc')+')');
            $('.gisName').children().show();
            $(".message").show();
            return;
        }
        var info = null;
        if (type == 'rq') {
            info = data.communitynamegetRqEixt
        } else if (type == 'poi') {
            info = data.label
        } else {
            info = data.communityName
        }
        var parentDiv = $('<div class='+id+'></div>');
        var childDiv = $('<div>' + info + '</div>');
        var childImg = $('<h6 oldsrc='+unSelectImgSrc+'></h6>');
        var sj = $('<p></p>');
        $('.MapWarp').append(parentDiv);
        parentDiv.append(childDiv);
        parentDiv.append(sj);
        childDiv.css('border', '1px solid #FF9000')
            .css('color', '#333')
            .css('padding', '6px 11px')
            .css('border-radius', '4px')
            .css('background', '#fff')
            .css('position', 'absolute')
            .css('top', '-38px')
            // .css('max-width', '118px')
            // .css('overflow', 'hidden')
            .css('white-space', 'nowrap')
            .css('text-overflow', 'ellipsis')
            .css('display', 'none')
            .css('cursor', 'pointer');

        sj.css('border-left', '10px solid transparent')
            .css('borderRight', '10px solid transparent')
            .css('borderTop', '10px solid #FF9000')
            .css('position', 'absolute')
            .css('left', '10px')
            .css('bottom', '36px')
            .css('display', 'none');
        parentDiv.append(childImg);
        parentDiv.css('position','absolute');
        childImg.css('background-image', 'url(' + unSelectImgSrc + ')')
            .css('background-repeat', 'no-repeat')
            .css('width', '40px')
            .css('height', '40px')
            .css('line-height', '28px')
            .css('text-align', 'center')
            .css('color', '#fff');
        parentDiv.hover(function () {
            $(this).css('z-index','10');
            childImg.css('background-image', 'url(' + selectImgSrc + ')')
            childDiv.css('left', -(childDiv.outerWidth() / 2 - 20))
            childDiv.css('z-index', '999');
            childDiv.show();
            sj.show();
        }, function () {
            $(this).css('z-index','auto');
            childImg.css('background-image', 'url(' + unSelectImgSrc + ')')
                .css('background-repeat', 'no-repeat')
                .css('width', '40px')
                .css('height', '40px')
                .css('line-height', '28px')
                .css('text-align', 'center')
                .css('color', '#fff');
            childDiv.hide();
            sj.hide();
        }).css('cursor', 'pointer').click(function () {
            if (type == 'poi') {
                return;
            }
            var communityId = data.community_id;
            var city = $('.cityTab .city').attr('value');
            $('.mapOutline').show();
            $('.mapSlide').hide();
            mainGlobal.map.getCommunity(communityId, city);
            var bound = data.bound;
            var x = data.x;
            var y = data.y;
            mapSource.communityBoundFeat(bound, x, y);
        });
        return parentDiv;
    },
    loadList: function (data, url,getSrc) {
        var json = data;
        var src;
        var content = '';
        json.sort(function(a, b){
            return a.distance - b.distance;
        });
        $(".row-content").html('');
        if(json.length == 0){
            $(".row-content").html('<img style="display: block;margin: 0 auto;padding-top: 50px;" src="../../assets/noData.png">');
        }
        json.forEach(function (item) {
            var info = item.N;
            var id = item.N.poi_id;
            var address = (info.address != null) ? info.address : '--';
            var label = (info.label != null) ? info.label : '--';
            var communityCenter = mapQuery.center;
            var po = item.N.geometry.A;
            var ep3 = new ol.proj.Projection({
                code: 'EPSG:3857'
            });
            var ep4 = new ol.proj.Projection({
                code: 'EPSG:4326'
            });
            var shp = new ol.Sphere(6378137);
            var c1 = ol.proj.transform(communityCenter, ep3, ep4);
            var c2 = ol.proj.transform(po, ep3, ep4);
            var distance = shp.haversineDistance(c1, c2);
            if (distance != null && distance != '') {
                distance = distance.toFixed(0);
            } else {
                distence = '--';
            }
            content = "<div class='row-detail' type="+id+" src="+getSrc+">" +

                "<div class='row-information'>" +
                "<div class='pull-left1'>" +
                "<span class='pull-left'><image src=" + url + "/></span>" +
                "<span class='row-font-name pull-left' title=" + label + ">" + label + "</span>" +
                "</div>" +
                "<div class='pull-right1'>" +
                "<span class='right-distance'><image src='/assets/distance_.png'/></span>" +
                "<span class='row-font-color'>" + distance + "米</span>" +
                "</div>" +
                "</div>" +
                "<div class='row-info'>" +
                address
            "</div>" +
            "</div>";
            $(".row-content").append(content);
        })
    },
}


